import api from '../../api';
import { message } from 'antd';

export const namespace = 'OperationalMonitoringLeverageAnalysisM';
export default {
  namespace,
  state: {},
  effects: {
    // 运营监控-查询分位数统计
    *queryQuantileStatistics({ payload, callback }, { call, put }) {
      const response = yield call(api.operationalMonitoringLeverageAnalysisApi.queryQuantileStatistics, payload);
      if (response && response.code == '0') {
        callback({
          dataSource: response.data,
          pageInfo: {
            total: response.data.length,
          },
        });
      } else {
        message.error(response?.msg || '查询分位数统计失败！');
        // const res = {
        //   dataSource: [
        //     {
        //       id: '111',
        //       maxLeverageRange: { min: 100, max: 170, judgeSymbol: 1 },
        //       averageLeverageRange: { min: 120, max: 190, judgeSymbol: 3 },
        //       maxQuantiles: 180,
        //       averageQuantiles: 70,
        //     },
        //     {
        //       id: '222',
        //       maxLeverageRange: null,
        //       averageLeverageRange: { min: null, max: null, judgeSymbol: null },
        //       maxQuantiles: 200,
        //       averageQuantiles: 100,
        //     },
        //   ],
        // };
        // callback(res);
        callback({
          dataSource: [],
          pageInfo: {
            total: 0,
          },
        });
      }
    },
    // 运营监控-收益贡献分析
    *queryRevenueAnalysis({ payload, callback }, { call, put }) {
      const response = yield call(api.operationalMonitoringLeverageAnalysisApi.revenueContributionAnalysis, payload);
      if (response && response.code == '0') {
        callback(response.data);
      } else {
        message.error(response?.msg || '查询收益贡献分析失败！');
        // const arr = [];
        // for (let i = 0; i < 27; i++) {
        //   arr.push({
        //     id: i,
        //     productType: 'fzxaHt',
        //     productName: 'NFtAEUl',
        //     productCode: 'etmnW',
        //     belongsTenant: '8!dlv',
        //     maxLeverage: 'P[zMRs',
        //     maxLeverageDate: '9yx^l',
        //     minLeverage: 'JGC',
        //     minLeverageDate: '$P#%',
        //     averageLeverage: 'St#',
        //     differenceLeverage: 'Rmfc',
        //     rangeYearRate: 0.26,
        //   });
        // }
        // const res = {
        //   dataSource: arr,
        //   pageInfo: {
        //     total: 27,
        //   },
        // };
        // callback(res);
        callback({
          dataSource: [],
          pageInfo: {
            total: 0,
          },
        });
      }
    },
    // 运营监控-倾向分析
    *queryPropensityAnalysis({ payload, callback }, { call, put }) {
      const response = yield call(api.operationalMonitoringLeverageAnalysisApi.propensityAnalysis, payload);
      if (response && response.code == '0') {
        callback(response.data);
      } else {
        message.error(response?.msg || '查询倾向分析失败！');
        // const arr = [];
        // for (let i = 0; i < 27; i++) {
        //   arr.push({
        //     id: `id-${i + 1}`,
        //     tenantName: i + 5,
        //     maxLeverage: i + 10,
        //     minLeverage: i + 20,
        //     averageLeverage: i + 30,
        //     differenceLeverage: i + 40,
        //   });
        // }
        // const res = {
        //   dataSource: arr,
        //   pageInfo: {
        //     total: 27,
        //   },
        // };
        // callback(res);
        callback({
          dataSource: [],
          pageInfo: {
            total: 0,
          },
        });
      }
    },
  },
  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
